package com.bdcom.aspect;

import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class CustomerAspect {
	
	@Pointcut("execution(* com.bdcom.planner.ApplicationFrame.init*(..))")
	private void initMethod(){}
	@Pointcut("execution(* com.bdcom.comp.InspectorPanel.*Model(..))")
	private void persistMethod(){}
	@Pointcut("execution(* com.bdcom.comp.CanvasPanel.draw*(..))")
	private void drawMethod(){}
	@Pointcut("drawMethod() || persistMethod()")
	private void exceptionMethod(){}
	//通知
	@Around("initMethod()")
	public void AroundInitMethod(ProceedingJoinPoint joinpoint) throws Throwable{
		
		Logger _log =Logger.getLogger(joinpoint.getTarget().getClass());
		
		_log.info("start "+joinpoint.getSignature().getName()+" Method!");
		
			joinpoint.proceed();
		
		_log.info("terminate "+joinpoint.getSignature().getName()+" Method!");
		
	}
	
	@AfterThrowing(pointcut="exceptionMethod()",throwing="ex")
	public void AfterthrowPlanerException(Exception ex,JoinPoint joinpoint){
			
		Logger _log =Logger.getLogger(joinpoint.getTarget().getClass());
		
		_log.error("Exception at "+joinpoint.getSignature().getName()+" case:"+ex.getLocalizedMessage());
		
	}

}
